package org.androidpeople.facebook;

import net.xeomax.FBRocket.FBRocket;
import net.xeomax.FBRocket.Facebook;
import net.xeomax.FBRocket.LoginListener;
import net.xeomax.FBRocket.ServerErrorException;
import android.app.Activity;
import android.os.Bundle;

public class FacebookRocketExample extends Activity implements LoginListener {

	private FBRocket fbRocket;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);

		shareFacebook();
	}

	public void shareFacebook() {
		fbRocket = new FBRocket(this, "PitchFork TRY",
				"c3968bbdd9dc7f44a8e05b7346f46673");

		if (fbRocket.existsSavedFacebook()) {
			fbRocket.loadFacebook();
		} else {
			fbRocket.login(R.layout.main);
		}
	}

	@Override
	public void onLoginFail() {
		fbRocket.displayToast("Login failed!");
		fbRocket.login(R.layout.main);
	}

	@Override
	public void onLoginSuccess(Facebook facebook) {
		// TODO Auto-generated method stub
		fbRocket.displayToast("Login success!");

		try {
			facebook.setStatus("This is your status");
			fbRocket.displayDialog("Status Posted Successfully!! "
					+ facebook.getStatus());
		} catch (ServerErrorException e) {
			if (e.notLoggedIn()) {
				fbRocket.login(R.layout.main);
			} else {
				System.out.println(e);
			}
		}
	}

}